package Demo3

import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.spark.{SparkConf, SparkContext}

/**
  * Created by lenovo on 2017/11/30.
  * 流式数据处理
  */
object SparkStreaming_scalaWC {
  def main(args: Array[String]) {
    val conf = new SparkConf().setMaster("local[2]").setAppName("SparkStreaming_scalaWC").set("spark.testing.memory","2147480000")
    val sc = new SparkContext(conf)
    val ssc = new StreamingContext(sc,Seconds(5))

   val paris = ssc.socketTextStream("hadoop1",2222)
   val words = paris.map(x => (x,1))
   val wordcounts = words.reduceByKey((x,y) => x+y)
    wordcounts.print()

    ssc.start()
    ssc.awaitTermination()

  }
}
